import com.ynny.mapper.StudentMapper;
import com.ynny.pojo.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class test {

    @Test
    public void test() throws IOException {

        // 需要 sqlSession sql会话
        InputStream resourceAsStream =
                Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sessionFactory =
                new SqlSessionFactoryBuilder().build(resourceAsStream);

        //开启会话
        SqlSession sqlSession =
                sessionFactory.openSession(true);

        //获取接口
        StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);

          Student student = new Student();

          //增
//        for (int i = 0; i < 1000; i++) {
//            Student student1 = new Student();
//            student1.setNumber("11111"+i);
//            student1.setName("张三"+i);
//            student1.setPassword("123456");
//            student1.setGrade("2019");
//            student1.setClbum("计算机");
//            student1.setGender("男");
//            student1.setType("学生");
//            studentMapper.insert(student1);
//        }


            //查
//        student.setName("田");
//        List<Student> students = studentMapper.selectAll(student);
//        for (Student student1 : students) {
//            System.out.println(student1);
//        }

        //改
//        student.setNumber("11112");
//        student.setName("田鸡");
//        student.setPassword("123456");
//        student.setGrade("2019");
//        student.setClbum("厕所门修理");
//        student.setGender("男");
//        student.setType("老师");
//
//        int i = studentMapper.updateBynumber(student);

        //删
        int i = studentMapper.deleteByNumber("11111999");

    }
}
